define(
    function (require) {
        var BaseFormModel = require('common/FormModel');
        var Data = require('./Data');
        var datasource = require('er/datasource');
        var u = require('underscore');
        var m = require('moment');

        function MallFormModel() {
            BaseFormModel.apply(this, arguments);
            var entityName = this.getUrlType();
            this.addData(new Data(entityName));
        }

        MallFormModel.prototype.prepare = function () {
            BaseFormModel.prototype.prepare.call(this);
            this.set('uploadUrl', '/api/upload/4');

            var districtid = this.get('districtid');
            if (u.isString(districtid)) {
                if (districtid.indexOf('_') === -1) {
                    districtid = 'district_' + districtid;
                }
                this.set('districtid', [districtid]);
            }

            this.prepareObject('chargePerson', 'director');
        };

        MallFormModel.prototype.uploaderIds = ['logo-pic', 'project-pic', 'id-pic1', 'id-pic2', 'qrcode'];

        MallFormModel.prototype.save = function(entity) {
            var date = entity.date;
            if (date) {
                entity.date = m(date).format('YYYYMMDD');
            }
            return BaseFormModel.prototype.save.apply(this, arguments);
        };

        MallFormModel.prototype.validateEntity = function (entity) {
            var errorMsg = [];

            var address = entity.address;
            if (!u.isObject(address)) {
                errorMsg.push(
                    {
                        field: 'address',
                        message: '请输入正确的地址'
                    }
                );
            }

            if (errorMsg.length > 0) {
                return errorMsg;
            }
            return BaseFormModel.prototype.validateEntity.apply(this, arguments);
        };

        require('er/util').inherits(MallFormModel, BaseFormModel);
        return MallFormModel;
    }
);
